package com.AllenDuke;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.AllenDuke.dao.impl.EmployeeDAOImpl;
import com.AllenDuke.proxy.EmployeeServiceProxy;
import com.AllenDuke.proxy.LogProxy;
import com.AllenDuke.service.impl.EmployeeServiceImpl;
import com.AllenDuke.tx.LogUtil;
import com.AllenDuke.tx.TransactionManger;

@Configuration
public class AppConfig {

	@Bean("EmployeeDAOImpl")
	public EmployeeDAOImpl getEmployeeDAOImpl() {
		EmployeeDAOImpl edi = new EmployeeDAOImpl();
		return edi;
	}

	@Bean("EmployeeServiceImpl")
	public EmployeeServiceImpl getEmployeeServiceImpl(EmployeeDAOImpl edi) {
		EmployeeServiceImpl esi = new EmployeeServiceImpl();
		esi.setDao(edi);
		return esi;
	}

	@Bean("TransactionManger")
	public TransactionManger getTransactionManager() {
		TransactionManger tm = new TransactionManger();
		return tm;
	}

	@Bean("EmployeeServiceProxy")
	public EmployeeServiceProxy getEmployeeServiceProxy(EmployeeServiceImpl esi, TransactionManger tm) {
		EmployeeServiceProxy esp = new EmployeeServiceProxy();
		esp.setTarget(esi);
		esp.setTm(tm);
		return esp;
	}

	@Bean("LogUtil")
	public LogUtil getLogUtil() {
		return new LogUtil();
	}

	@Bean("LogProxy")
	public LogProxy getLogProxy(EmployeeServiceImpl esi, LogUtil lu) {
		LogProxy lg = new LogProxy();
		lg.setTarget(esi);
		lg.setLu(lu);
		return lg;
	}

}